#ifndef DKM_SPRITE_H
#define DKM_SPRITE_H

#include "Engine.h"

namespace dkm
{
	class Sprite: public Component
	{
	public:
		//You can specify a texture or a path name to the Sprite.
		//If you don't specify visible and active, they are true by default.
		Sprite(const string imgSrc, ID3DXSprite* mSprite, const float x, const float y, const float width, const float height, const float rotation, const float scaleX, const float scaleY, const bool visible, const bool active);
		Sprite(IDirect3DTexture9* texture, ID3DXSprite* mSprite, const float x, const float y, const float width, const float height, const float rotation, const float scaleX, const float scaleY, const bool visible, const bool active);
		Sprite(const string imgSrc, ID3DXSprite* mSprite, const float x, const float y, const float width, const float height, const float rotation, const float scaleX, const float scaleY);
		Sprite(IDirect3DTexture9* texture, ID3DXSprite* mSprite, const float x, const float y, const float width, const float height, const float rotation, const float scaleX, const float scaleY);
		virtual ~Sprite();

		virtual void Update(const float dt) = 0;
		virtual void Draw();

		//DrawBatched is called by SpriteGroup, it does not flush the ID3DXSprite.
		virtual void DrawBatched();

		//Apply the required transformations as set in drawMode to the sprite.
		void Transform();

		void X(const float x) { this->x = x; }
		void Y(const float y) { this->y = y; }
		void Depth(const float depth) { this->depth = depth; }
		void Rotation(const float rotation) { this->rotation = rotation; }
		void ScaleX(const float scaleX) { this->scaleX = scaleX; }
		void ScaleY(const float scaleY) { this->scaleY = scaleY; }
		float X() const { return x; }
		float Y() const { return y; }
		float Rotation() const { return rotation; }
		float ScaleX() const { return scaleX; }
		float ScaleY() const { return scaleY; }
		void AddX(const float x) { this->x += x; }
		void AddY(const float y) { this->y += y; }
		void AddRotation(const float rotation) { this->rotation += rotation; }
		void AddScaleX(const float scaleX) { this->scaleX += scaleX; }
		void AddScaleY(const float scaleY) { this->scaleY += scaleY; }
		void ResetScale() { ScaleX(0.0f); ScaleY(0.0f); }
		void ResetPos() { X(0.0f); Y(0.0f); }
		void SetScale(const float scaleX, const float scaleY) { ScaleX(scaleX); ScaleY(scaleY); }
		void SetPos(const float x, const float y) { X(x); Y(y); }
		void SetBatched(const bool batched) { this->isBatched = batched; }
		void Move(const float x, const float y) { AddX(x); AddY(y); }
		void Scale(const float scaleX, const float scaleY) { AddScaleX(scaleX); AddScaleY(scaleY); }
		void SetRect(const bool useRect, const float left, const float top, const float right, const float bottom);
		void SetRect(const bool useRect);

		void Texture(const string imgSrc) { this->texture = Engine::GetInstance()->GetTex(imgSrc); }
		void SetDrawMode(const string drawMode) { this->drawMode = drawMode; }
	
	private:
		ID3DXSprite* dxSprite;
		IDirect3DTexture9* texture;
		float x;
		float y;
		float depth;
		float width;
		float height;
		float rotation;
		float scaleX;
		float scaleY;
		string drawMode;
		bool isBatched;
		D3DXVECTOR3 pos;
		D3DXVECTOR3 center;
		D3DXMATRIX R,T,S;
		bool useRect;
		RECT r;
	};

}

#endif